typedef struct Dijkstra
{
    int n;
    vector<vector<pair<int, int>>> e;
    vector<int> dist;
    Dijkstra(int n) : n(n + 1), e(2 * n + 1), dist(n + 1, 1e18) {}
    void addU(int u, int v, int w)
    {
        e[u].push_back({v, w});
        e[v].push_back({u, w});
    }
    void addD(int u, int v, int w)
    {
        e[u].push_back({v, w});
    }
    int dijk(int s)
    {
        priority_queue<pii, vector<pii>, greater<pii>> q;
        q.push({0, s});
        dist[s] = 0;
        while (q.size())
        {
            auto [d, u] = q.top();
            q.pop();
            if (dist[u] < d)
                continue;
            for (auto [v, w] : e[u])
            {
                if (dist[v] > d + w)
                {
                    dist[v] = d + w;
                    q.push({d + w, v});
                }
            }
        }
    }
    int qdist(int x)
    {
        return dist[x];
    }
} G;